package com.atguigu.gulimall.order.vo;

import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Data
public class OrderConfirmVo {
    /**
     * 用户地址列表
     */
    private List<MemberAddressVo> addresses;

    /**
     * 订单项信息
     */
    private List<OrderItemVo> items;

    // todo 发票信息

    /**
     * 优惠卷信息 积分
     */
    private Integer integration;

    /**
     * 订单 防重token
     */
    private String orderToken;

    /**
     * 库存有货/无货信息
     */
    private Map<Long, Boolean> stocks;

    /**
     * 商品数量
     */
    @Getter(value = AccessLevel.NONE)
    private Integer count;

    /**
     * 订单总额
     */
    @Getter(value = AccessLevel.NONE)
    private BigDecimal totalPrice;

    /**
     * 支付金额
     */
    @Getter(value = AccessLevel.NONE)
    private BigDecimal payPrice;


    public Integer getCount() {
        int cnt = 0;
        if (items != null && !items.isEmpty()) {
            for (OrderItemVo item : items) {
                cnt += item.getCount();
            }
        }
        return cnt;
    }

    public BigDecimal getTotalPrice() {
        BigDecimal sum = BigDecimal.ZERO;
        if (items != null && !items.isEmpty()) {
            for (OrderItemVo item : items) {
                sum = sum.add(item.getTotalPrice());
            }
        }
        return sum;
    }

    public BigDecimal getPayPrice() {
        return getTotalPrice();
    }

    @Data
    public static class MemberAddressVo {
        /**
         * id
         */
        private Long id;
        /**
         * member_id
         */
        private Long memberId;
        /**
         * 收货人姓名
         */
        private String name;
        /**
         * 电话
         */
        private String phone;
        /**
         * 邮政编码
         */
        private String postCode;
        /**
         * 省份/直辖市
         */
        private String province;
        /**
         * 城市
         */
        private String city;
        /**
         * 区
         */
        private String region;
        /**
         * 详细地址(街道)
         */
        private String detailAddress;
        /**
         * 省市区代码
         */
        private String areacode;
        /**
         * 是否默认
         */
        private Integer defaultStatus;
    }

    @Data
    public static class OrderItemVo {
        private Long skuId;
        private String title;
        private String image;
        private List<String> skuAttrs;
        private BigDecimal price;
        private Integer count;
        private BigDecimal totalPrice;

        private BigDecimal weight;

    }
}
